<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>故障处理流程</title>
  <link href="css/layui.css" rel="stylesheet" type="text/css" />
  <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <form class="layui-form p20 lineBox" action="" lay-filter="addFaultPointForm">
          <div class="layui-card">
            <div class="layui-card-header">
              <p class="title-row"> 故障点基础信息</p>
            </div>
            <div class="layui-card-body">
              <div class="layui-inline">
                <label class="layui-form-label">故障线路</label>
                <div class="layui-input-block">
                  <select name="faultRoute" id="faultRoute" lay-filter="faultRouteFilter" lay-search=""
                    lay-verify="faultRoute">

                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">故障地点</label>
                <div class="layui-input-block">
                  <select name="station" id="station" lay-filter="stationFilter" lay-search="" lay-verify="required">
                    <option value="">请先选择线路</option>

                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">故障类型</label>
                <div class="layui-input-inline">
                  <!-- <input type="text" name="faultType" placeholder="请选择故障类型" autocomplete="off" class="layui-input"
                    lay-verify="required"> -->
                    <select name="faultType" id="faultType" lay-filter="faultTypeFilter" lay-search="" lay-verify="required">
                      <option value="">请选择故障类型</option>
                      <option value="车辆">车辆</option>
                      <option value="调度">调度</option>
                      <option value="供配电">供配电</option>
                      <option value="轨道">轨道</option>
                      <option value="驾驶班">驾驶班</option>
                      <option value="接触网">接触网</option>
                      <option value="列车辅助设备">列车辅助设备</option>
                      <option value="桥梁">桥梁</option>
                      <option value="通信">通信</option>
                      <option value="通信、信号">通信、信号</option>
                      <option value="土建">土建</option>
                      <option value="网络">网络</option>
                      <option value="物业">物业</option>
                      <option value="信号">信号</option>
                      <option value="专职抢修队">专职抢修队</option>  
                    </select>
                </div>
              </div>
            </div>

            <div class="layui-card-header">

              <p class="title-row">故障点描述</p>
            </div>

            <div class="layui-card-body">
              <div class="layui-form-item layui-form-text textBox">
                <textarea name="desc" placeholder="请输入内容" class="layui-textarea" lay-verify="required|formTextLength"></textarea>
              </div>

              <div class="layui-form-item">
                <div class="layui-input-block sumitBtn">
                  <button class="layui-btn confirmButton" lay-submit lay-filter="formSubmit" type="button">确认</button>
                  <button type="reset" class="layui-btn layui-btn-primary closePage" type="button">取消</button>
                </div>

              </div>
            </div>
          </div>
        </form>

      </div>
    </div>
  </div>

  <script src="layui.js"></script>
  <script src="json/lineStation.js"></script>
  <script src="index.js"></script>
  <script>

    var num = 4;
    //一般直接写在一个js文件中
    layui.use(['layer', 'form'], function () {
      var layer = layui.layer
        , $ = layui.$
        // , table = layui.table //表格
        , form = layui.form;

      $('.closePage').on('click', function () {
        closeSonPage();
      });

      generateLineNo($);

      function closeSonPage() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
      }


      //下拉框非空验证
      form.verify({
        faultRoute: function (value, item) {
          if (value == 0) {
            return "必选项不能为空"
          }
        },
        formTextLength: function (value) {
          let i,sum;
          sum=0;
          for(i=0;i<value.length;i++){
            if ((value.charCodeAt(i)>=0) && (value.charCodeAt(i)<=255)){
              sum=sum+1;
            } else {
              sum=sum+2;
            }
          }
          if (sum > 200) {
            return '故障点相关备注最多只能200个字符或者100个中文字';
          }
        }
      });

      //监听提交
      form.on('submit(formSubmit)', function (data) {
      
        var paramData = data.field;
        // if(paramData.faultRoute < 18){
        //   paramData.faultRoute += '号线'
        // }
        if(!$(this).attr('lock')){
          $(this).attr('lock',true);
          $.ajax({
            url: getIP() + '/fault/addFaultPoint',
            type: 'get',
            // data: { faultId: paramData.faultId, flowLinkId: paramData.tag, choice: "delete" },

            data: { faultLine: paramData.faultRoute, faultLocation: paramData.station, faultType: paramData.faultType, faultContent: paramData.desc },
            contentType: 'application/x-www-form-urlencoded',
            success: function (data) {
              if (data.code == 'success') {
                layer.msg(data.msg, { time: 900, icon: 6 }, function () {
                  window.parent.refreshData();
                  closeSonPage();
                  //layer.closeAll('page');
                });//失败的表情5 成功的表情6
                return;
              } else {
                layer.msg(data.msg, { icon: 5 });//失败的表情5 成功的表情6
                return;
              }
            },
          });
          $(this).attr('lock',false);
        }
        return false;
      });


      form.on('select(faultRouteFilter)', function (data) {
        generateStation(data.value, $);
      });



    });






  </script>
</body>

</html>